package com.tongzhou.tongzhou.quot.dao.impl;

import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.tongzhou.db.DBUtil;
import com.tongzhou.db.exception.DBException;
import com.tongzhou.tongzhou.quot.dao.IPaperNumberPriceDAO;
import com.tongzhou.tongzhou.quot.model.PaperNumberPrice;
import com.tongzhou.util.Util;

public class PaperNumberPriceDAO implements IPaperNumberPriceDAO{
	
	public int addPaperNumberPrice(PaperNumberPrice paperNumberPrice) throws DBException {
		StringBuffer sql=new StringBuffer();
		sql.append("insert into paper_number_price(number,price1,price2,create_time) ");
		sql.append("values('"+Util.changeToObj(paperNumberPrice.getNumber())+"',");
		sql.append("'"+Util.changeToObj(paperNumberPrice.getPrice1())+"',");
		sql.append("'"+Util.changeToObj(paperNumberPrice.getPrice2())+"',now())");
		int result=DBUtil.update(sql.toString());
		return result;
	}

	public void deletePaperNumberPrice() throws DBException {
		StringBuffer sql=new StringBuffer();
		sql.append("delete from paper_number_price ");
		DBUtil.update(sql.toString());
		DBUtil.update(sql.toString());
	}

	public List<PaperNumberPrice> getPaperNumberPriceList() throws DBException {
		StringBuffer sql=new StringBuffer();
		sql.append("select id,number,price1,price2,create_time from paper_number_price ");
		sql.append(" where 1=1 ");
		sql.append(" order by id asc ");
		List<PaperNumberPrice> result=DBUtil.query(sql.toString(),new BeanListHandler<PaperNumberPrice>(PaperNumberPrice.class));
		return result;
	}
}
